home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-30 | 10.4 KB | 235 lines | [TEXT/MPS ] |
- {[j=20/53/1$] PasMat Options}
-
- PROGRAM FracApp;
-
- {-------------------------------------------------------------------------------------------
-
- Program: FracApp 2.0
- Unit: FracApp main program
- File: MFracApp.p
-
- by Keith Rollin & Bo3b Johnson
- of Apple Macintosh Developer Technical Support
-
- Copyright © 1988-1990 Apple Computer, Inc.
- All rights reserved.
-
- --------------------------------------------------------------------------------------------
-
- This is the Main part of the program. Its job is to make sure that we’re running on
- an OK machine and, if so, initialize all the parts of MacApp we need, make an
- application object, and run it. When TFracAppApplication.Run returns, that means that
- the user has selected “Quit”, that everything is shut down, and that all we have to
- do is get out of here. If the machine type is not OK, then we put up an alert saying
- what is wrong.
-
- --------------------------------------------------------------------------------------------}
-
- { Our main program has to be able to run on any machine, so that we can at
- least tell people that they can’t run on this machine. Therefore, make sure
- that we turn off 68020 and 68881 code generation. }
-
- {$MC68881-}
- {$MC68020-}
-
- USES
- { • MacApp Interfaces • }
- UMacApp, UDialog, UPrinting,
-
- { • ToolBox Interfaces • }
- PaletteMgr, Resources, ToolUtils, Packages, QDOffscreen,
-
- { • FracApp Interfaces • }
- UOffscreen, URectStack, UFracApp;
-
- CONST
- kUnsupportedMac = - 25001;
- kCompiledWrong = - 25003;
-
- VAR
- gFracAppApplication: TFracAppApplication;
-
- {-------------------------------------------------------------------------------------------}
- {$S AInit}
-
- PROCEDURE MyInitUDialog;
-
- { This routine is here to replace the standard InitUDialog that comes with
- MacApp. The standard routine suppresses dead-code stripping on ALL UDialog
- classes. However, I know that I don’t use all of them in FracApp, and so don’t
- mind if the linker dead-code strips some of them. Using this alternate
- InitUDialog routine reclaims about 5.5K in my final program.
-
- So what is all this “dead-code stripping” suppression all about. What code is
- being dead-code stripped, and why is it so important to suppress it?
-
- Dead-code stripping the is act of the linker removing all code that doesn’t
- appear to be accessed in any way. This is normally a good feature, as it
- allows us to link with large libraries (such as MacApp.Lib), taking only what
- we need and leaving everything else behind.
-
- However, if we are creating our views via resources, it’s possible for too
- much of MacApp.Lib or our program to get dead-code stripped. For instance, in
- the view resource for one of my dialogs, I have a reference to TIcon.
- However, nowhere in my program nor MacApp is there an explicit reference to
- TIcon. Sure, there are the definitions for the TIcon methods themselves, but
- nowhere are there any TIcon variables, or TViews being coerced into TIcons.
- This means that the linker will strip out all code that is associated with
- TIcon. When it comes time for MacApp to read in the ‘view’ resource and
- create my dialog, it will fail because all the code’s been stripped.
-
- The solution is to force a reference of some sort to all the views that are
- created via resources. We do this with the following “Member” instructions.
- So that we don’t actually execute those commands (it’s not necessary to
- execute the commands - they just need to exist so the linker sees the
- reference to our view sub-classes), we condition them on the variable called
- “gDeadStripSuppression”. This variable is AWAYS FALSE, so the “IF Member(...)”
- statements will never get executed. So why go through the trouble of making
- a variable if its always going to be FALSE? Well, if we used a constant
- there, the linker would get it into it’s head that it’s found code that will
- NEVER be executed and ... yep ... strip it out. So it chucks out the code
- that is keeping other parts of our code from being stripped out. Which means
- that they end up getting thrown out after all. So we use a variable to
- condition the execution of the following statement, because then the linker
- won’t know for sure if the condition will be TRUE or FALSE.
-
- MyInitUDialog is an exact copy of the standard InitUDialog. I've just
- commented out the commands that suppress dead-code stripping of views
- that I’ll never need. There is a danger to this, though. If someone were
- to take the final version of FracApp and do something like change the
- About Box Dialog to have a TPicture in it, FracApp would fail, as the
- code to handle it would have been removed. But that’s a risk I’m prepared
- to take. }
-
- BEGIN
- IF qTemplateViews THEN BEGIN
-
- { So the linker doesn’t dead strip these }
-
- IF gDeadStripSuppression THEN BEGIN
- IF Member(TObject(NIL), TDialogView) THEN;
- IF Member(TObject(NIL), TControl) THEN;
- IF Member(TObject(NIL), TButton) THEN;
- { IF Member(TObject(NIL), TCheckBox) THEN; }
- { IF Member(TObject(NIL), TRadio) THEN; }
- { IF Member(TObject(NIL), TCluster) THEN; }
- IF Member(TObject(NIL), TIcon) THEN;
- { IF Member(TObject(NIL), TPicture) THEN; }
- { IF Member(TObject(NIL), TPopup) THEN; }
- IF Member(TObject(NIL), TStaticText) THEN;
- IF Member(TObject(NIL), TEditText) THEN;
- IF Member(TObject(NIL), TNumberText) THEN;
- { IF Member(TObject(NIL), TPattern) THEN; }
- END;
-
- RegisterStdType('TDialogView', kStdDialogView);
- RegisterStdType('TControl', kStdControl);
- RegisterStdType('TButton', kStdButton);
- { RegisterStdType('TCheckBox', kStdCheckBox); }
- { RegisterStdType('TRadio', kStdRadio); }
- { RegisterStdType('TCluster', kStdCluster); }
- RegisterStdType('TIcon', kStdIcon);
- { RegisterStdType('TPicture', kStdPicture); }
- { RegisterStdType('TPopup', kStdPopup); }
- RegisterStdType('TStaticText', kStdStaticText);
- RegisterStdType('TEditText', kStdEditText);
- RegisterStdType('TNumberText', kStdNumberText);
- { RegisterStdType('TPattern', kStdPattern); }
- END;
-
- gUDialogInitialized := TRUE;
- END;
-
- {-------------------------------------------------------------------------------------------}
- {$S Main}
-
- BEGIN
-
- { Initialize the standard Macintosh Managers. This does the typical InitGraf
- business, as well as initializing MacApp’s global variables. InitToolBox also
- makes sure that we have at least enough memory to do some intelligent failing
- (for example, in StdAlert below). If there isn’t, MacApp just calls
- ExitToShell. Calling InitToolBox is required in MacApp programs. }
-
- InitToolBox;
-
- { Check to see that we were compiled with the right options. FracApp absolutely
- positively needs to be compiled for Color QuickDraw and an FPU. We take
- advantage of 32-bit Color QuickDraw if it’s around, but we don’t require it.
- If FracApp was compiled with the wrong options, put up a dialog saying so,
- and quit the application. }
-
- IF NOT (qNeedsColorQD & qNeedsFPU) THEN BEGIN
- StdAlert(kCompiledWrong);
- ExitToShell;
- END;
-
- { InitToolBox has filled in a global variable call “gConfiguration”. This
- record contains a lot of information on what is available on the Macintosh we
- are running on. What we do next is call ValidateConfiguration to make sure
- that the machine features this program requires are actually available.
- ValidateConfiguration is self-configuring based on the compiler options you
- used to compile this program. If a feature is missing, ValidateConfiguration
- returns FALSE. For instance, we compile FracApp with the -NeedsColorQD
- option. If we try to run FracApp on a machine that doesn’t have Color
- QuickDraw, then ValidateConfiguration returns FALSE. Otherwise, it returns
- TRUE, and we can safely run on this machine.
-
- We also test here to see if we are running on a machine that has an FPU. We
- don’t require that you actually COMPILE FracApp with the -NeedsFPU option,
- but there are some assembly routines that get compiled with 68881 code, and
- those pieces need to be run on a machine with an FPU. If you don’t put
- -NeedsFPU on the MABuild command line, then ValidateConfiguration won’t check
- for an FPU. Therefore, we do it ourself by hand. }
-
- IF ValidateConfiguration(gConfiguration) & gConfiguration.hasFPU THEN BEGIN
-
- { When a Macintosh application is launched, any windows it puts up will
- initially appear behind the windows of any other running applications being
- run under MultiFinder. This is because MultiFinder hasn’t had a chance yet to
- tell the foremost application that it’s being sent to the back. In order to
- get our application’s windows to the front, we call PullApplicationToFront. }
-
- PullApplicationToFront;
-
- { We now continue with the rest of MacApp’s initialization. Calling InitUMacApp
- is required. It takes a single parameter which is the number of times that
- MoreMasters should be called. InitUPrinting, InitUDialog, and InitUTEView
- setup their respective units, and only need to be called if you will be using
- any of their services. Forgetting to call InitUDialog is a particularly
- common problem that is tricky to detect. Many times, you’ll introduce a
- dialog to your program, and forget to call InitUDialog. You’ll also need to
- call InitUTEView if you use any TEditText items, not just TTEViews. If you
- forget to do any of this, you’ll find that the various views that appear in
- dialogs will get stripped out by the Linker, and your program will crash
- mysteriously. If you have a program that works in Debug mode, but not in
- Non-Debug, then this is most likely the problem. }
-
- InitUMacApp(8);
- InitUPrinting;
- InitUTEView;
- MyInitUDialog;
-
- { Finally, we create our application object, initialize it, and run it. From
- this point on, MacApp is in control. When the user selects Quit from the
- menu, we come back to here, where all we have to do exit. }
-
- New(gFracAppApplication);
- FailNIL(gFracAppApplication);
- gFracAppApplication.IFracAppApplication(kFileType);
- gFracAppApplication.Run;
-
- END
- ELSE BEGIN
-
- { We aren’t running on the right kind of machine. We need at least Color
- QuickDraw and an FPU to run. 32-bit Color QuickDraw is supported, but it’s
- not necessary. If we can’t run on this machine, we show an alert saying why
- not, and quit. We use StdAlert for this (which is the MacApp bottleneck
- procedure for displaying alerts) so that we have control over the specific
- text in the message. }
-
- StdAlert(kUnsupportedMac);
- END;
- END.
-